package com.heima.behavior.service.impl;

import com.heima.behavior.dto.FollowBehaviorDto;
import com.heima.behavior.entity.ApFollowBehavior;
import com.heima.behavior.mapper.ApFollowBehaviorMapper;
import com.heima.behavior.service.IApBehaviorEntryService;
import com.heima.behavior.service.IApFollowBehaviorService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * APP关注行为表 服务实现类
 * </p>
 *
 * @author syl
 * @since 2022-01-03
 */
@Service
public class ApFollowBehaviorServiceImpl extends ServiceImpl<ApFollowBehaviorMapper, ApFollowBehavior> implements IApFollowBehaviorService {

    @Autowired
    private IApBehaviorEntryService behaviorEntryService;

    @Override
    public void saveFollowBehavior(FollowBehaviorDto dto) {


        ApFollowBehavior followBehavior = new ApFollowBehavior();

//        当前登录人是否有实体，如果有直接获取实体的id，如果没有需要创建实体


        Integer entryId = behaviorEntryService.getEntryByUserIdOrEquipmentId(dto.getUserId(),dto.getEquipmentId());
        followBehavior.setEntryId(entryId); //实体 id
        followBehavior.setFollowId(dto.getFollowId()); //关注的作者id
        followBehavior.setOperation(dto.getOperation());
        followBehavior.setCreatedTime(new Date());
        this.save(followBehavior);
    }
}
